<?php
/**
 * The template for displaying all pages.
 *
 * This is the template that displays all pages by default.
 * Please note that this is the WordPress construct of pages
 * and that other 'pages' on your WordPress site will use a
 * different template.
 *
 * @package WordPress
 * @subpackage Twenty_Twelve
 * @since Twenty Twelve 1.0
 */

global $post , $current_user;
if(!is_user_logged_in()){
    header("location:".get_permalink(get_page_id("dang-ky-thanh-toan")));
}

$list_like=get_user_meta($current_user->data->ID,"list-like-post",true);

get_header(); ?>
	<?php woo_main_before();?>
    <div class="row-fluid page-cart">
  		<div class="span3">
       			<?php get_template_part("content-mycount"); ?>
        </div>
    	<div id="primary" class="site-content span9">   
    		<div id="content" role="main">
                <header id="product-title" class="cart-title">
                    <h2 class="fl" style="font-size:14px;"><img width="40" src="<?php echo get_template_directory_uri() ?>/images/title_wishlist.png" /> Danh sách yêu thích của tôi </h2>
                </header>
    			<section id="main">
                <div class="row-fluid"> 			
               		<table class="mts wishlistTable ui-grid ui-gridFull" style="display:table">
                        <thead class="wishlistHead">
                            <tr id="title-wish">
                                <th class="article txtLeft ui-borderLeft ui-borderTop">Sản phẩm</th>
                                <th class="date txtLeft ui-borderTop">Ngày</th>
                                <th class="available txtLeft ui-borderTop">Tình trạng hàng</th>
                                <th class="price txtLeft ui-borderTop">Giá </th>
                                <th class="addToCart txtLeft ui-borderTop ui-borderRight"></th>
                            </tr>
                        </thead>
                        <tbody class="wishlistItems">
                        <?php if($list_like) { ?>
							<?php foreach ($list_like as $wishlist) { ?>
                            <?php $data=get_post($wishlist["id_product"]);
							      $price=show_format_price($data->ID,'price_one');
								  $images = json_decode($data->post_excerpt,true); 	
								  $axe=get_id_first($images);
								  $size=get_term_by( "id", $wishlist['size'],"size");
								  list($src) = wp_get_attachment_image_src($axe[1],"thumbnail");
								  list($count_size)=json_decode(get_post_meta($wishlist["id_product"],'size-product',true),true);
								  $number_sizeof_product=$count_size[$size->parent][$wishlist['size']];
								 /* ===================== Debug count size of product ================== */
								 /* echo '<pre>';
								  print_r($size);
								  echo '</pre>';
								  echo "------------------------------";
								  echo '<pre>';
								  print_r($wishlist);
								  echo '</pre>';
								  echo "------------------------------";
								  echo '<pre>';
								  print_r($count_size);
								  echo '</pre>';
								  echo "------------------------------";
								  echo $count_size[$size->parent][$wishlist['size']];
								  break;*/
								  /* ===================== Debug count size of product ================== */
							 ?>
                               <tr>
                                    <td class="article ui-border">
                                    	<div class="row-fluid imuys">
                                        	<div class="span4">
                                            	<a href="<?php echo get_permalink($wishlist["id_product"]) ?>"><img  alt="<?php echo $data->post_title; ?>" src="<?php echo $src ?>" /></a>
                                            </div>
                                            <div class="span7">
                                            	<h4><a href="<?php echo get_permalink($wishlist["id_product"]) ?>" title="<?php echo $data->post_title; ?>"><?php echo $data->post_title; ?></a></h4>
                                                <div>Kích cỡ: <?php echo $size->name ?></div>
                                                <div class="remove_list">
                                                	<img class="icon_remove_list" src="<?php echo get_template_directory_uri() ?>/images/remove.gif" />
                                                    <img class="icon_remove_wish" src="<?php echo get_template_directory_uri() ?>/images/icon_remove_wish.jpg" />
                                                	<a id="<?php echo $size->name ?>" onclick="return remove_list_tmp(this)" href="#"><img src="<?php echo get_template_directory_uri() ?>/images/icon_remove.jpg" /> Loại bỏ sản phẩm</a>
                                                	<div class="mess_list">
                                                    	<div class="opoiui">
                                                            <div class="mess_yes"><a title="<?php echo $current_user->data->ID ?>" onclick="return remove_list_yes(this)" id="<?php echo $size->term_id ?>"  href="#">Yes</a></div>	
                                                            <div class="mess_no"><a  onclick="return remove_list_no(this)"  id="<?php echo $size->name ?>" href="#">No</a></div>
                                                    	</div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </td>
                                    <td class="date ui-borderTop ui-borderBottom ui-borderRight"><?php echo $wishlist['time'] ?> </td>
                                    <?php if($number_sizeof_product<=0) {?>
                                    <td class="availability ui-borderTop ui-borderBottom ui-borderRight yes hh">Hết hàng</td>
                                    <?php } else { ?>
                                    <td class="availability ui-borderTop ui-borderBottom ui-borderRight yes ch">Còn hàng</td>
                                    <?php } ?>
                                    <td class="price ui-borderBottom ui-borderTop"><?php echo $price; ?></td>
                                    <td class="addToCart ui-border"></td>
                               </tr>
                            <?php } ?>   
                     	<?php } else { ?>
                        	<tr>
                            	<td colspan="5" style="font-style:italic;">Bạn chưa thích sản phẩm nào ! </td>
                            </tr>	
                        <?php } ?>
                        
                        </tbody>
                        <tbody class="wishlistItems">
                        	
                        </tbody>
                    </table>
                </div>
            	</section>
    		</div>
                
            <?php woo_main_after();?>
    	</div><!-- #primary -->
    </div>
    <hr />
<?php get_footer(); ?>
